<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\BookmarkController;
use App\Http\Controllers\CategoryController;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
api资源路由 https://learnku.com/docs/laravel/8.x/controllers/9368#resource-controllers
路由缓存和清除：
php artisan route:cache
php artisan route:clear
*/

// 必须要匿名才能访问的路由，未登录用户才能注册或登录
Route::post('auth/register', [AuthController::class, 'signup']);
Route::post('auth/login', [AuthController::class, 'login']);
Route::get('users/{id}', [UserController::class, 'show']);
Route::apiResource('bookmarks', BookmarkController::class)->only(['index', 'show']);
Route::apiResource('categories', CategoryController::class)->only(['index', 'show']);

// 必需登录验证之后才能访问的路由，由 auth:sanctum 看守器验证是否具有有效的 token
Route::middleware(['auth:sanctum'])->group(function () {
    Route::get('auth/logout', [AuthController::class, 'logout']);
    Route::get('auth/user', [AuthController::class, 'user']); // 当前登录用户信息
    Route::apiResource('users', UserController::class)->except(['show']);
    Route::apiResource('bookmarks', BookmarkController::class)->only(['create', 'store', 'update', 'destroy']);
    Route::apiResource('categories', CategoryController::class)->only(['create', 'store', 'update', 'destroy']);
});